import { Controller, Get, Post, Body, Patch, Param, Delete,Req ,Query, Res} from '@nestjs/common';
import { DictDataService } from './dict-data.service';
import { CreateDictDataDto } from './dto/create-dict-data.dto';
import { UpdateDictDataDto } from './dto/update-dict-data.dto';
import { QueryDictDataDto } from './dto/query-dict-data.dto';
import { ApiTags,ApiOperation,ApiBearerAuth } from '@nestjs/swagger';
import { Request,Response } from 'express';
import { DeleteDictDataDto } from './dto/delete-dict-data.dto';
import { StatusChangeDto } from 'src/common/baseDto/status-change.dto';

@ApiTags('字典数据')
@ApiBearerAuth()
@Controller('dict-data')
export class DictDataController {
  constructor(private readonly dictDataService: DictDataService) {}

  @Post('add')
  @ApiOperation({summary:'新增字典数据'})
  create(@Body() createDictDataDto: CreateDictDataDto,@Req() req:Request) {
    return this.dictDataService.create(createDictDataDto,req);
  }

  @Get()
  @ApiOperation({summary:'获取字典数据列表'})
  findAll(@Query() query:QueryDictDataDto) {
    return this.dictDataService.findAll(query);
  }

  @Get(':id')
  @ApiOperation({summary:'获取字典数据详情'})
  findOne(@Param('id') id: string) {
    return this.dictDataService.findOne(+id);
  }

  @Patch(':id')
  @ApiOperation({summary:'更新字典数据'})
  update(@Param('id') id: string, @Body() updateDictDataDto: UpdateDictDataDto,@Req() req:Request) {
    return this.dictDataService.update(+id, updateDictDataDto,req);
  }

  @Post('statusChange')
  @ApiOperation({ summary: '更新字典数据状态' })
  statusChange(@Body() statusChangeDto: StatusChangeDto,@Req() req:Request) {
    return this.dictDataService.statusChange(statusChangeDto,req);
  }

  @Post('delete')
  @ApiOperation({summary:'删除字典数据'})
  remove(@Body() deleteDictDataDto: DeleteDictDataDto) {
    return this.dictDataService.remove(deleteDictDataDto);
  }

  @Post('excel')
  @ApiOperation({ summary: '导出字典数据' })
  exportToExcel(@Res() res: Response) {
    return this.dictDataService.exportToExcel(res);
  }

  @Post('getDcit')
  @ApiOperation({ summary: '根据字典类型获取字典数据' })
  getDcitData(@Body() body: {
    dict_type: string;
  }) {
    return this.dictDataService.getDcitData(body.dict_type);
  }
}
